home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 235_02 / ovwin.c < prev    next >
Text File  |  1987-06-16  |  34KB  |  952 lines

  1. /*  034  14-Feb-87  ovwin.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4. */
  5.  
  6. #include <setjmp.h>
  7. #include <dos.h>
  8. #include "ov.h"
  9.  
  10. #ifndef NULL
  11. #define NULL (0)
  12. #endif
  13.  
  14. #define V_bar (0xba)
  15. #define H_bar (0xcd)
  16.  
  17. int diridx = 0;                        /* # dir names when showall */
  18. char **dirlst = NULL;                  /* ptr to dir name ptrs when showall */
  19.  
  20. static int win_update;                         /* NZ if refresh_screen update */
  21. static unsigned char inwin = 0;                /* # active info windows */
  22. static unsigned char numwin = 1;               /* # active windows */
  23. static WINDOW *curwin = NULL, *winlis = NULL, *winp;
  24.  
  25. static char *tdir;                             /* target dir */
  26. static char *tname;                            /* target name */
  27. static FILE_ENT holdf;                         /* save file_ent */
  28.  
  29. static char *nomem = "Insufficient memory for another window, no window created!";
  30. static char *noaccess = "Unable to access specified directory: ";
  31.  
  32. extern WINDOW cw;
  33. extern int winupdate;
  34. extern FILE_ENT files[];
  35. extern unsigned dataseg;
  36. extern jmp_buf back_to_main;
  37. extern unsigned char anyshowall;
  38.  
  39. char far *malloc_f();
  40. int ALTCALL scanwindows(), ALTCALL win_switch();
  41. int addfile_ent(), delfile_ent(), refresh_window();
  42. char *strrchr(), *strchr(), *parsepath(), *findir();
  43. int ALTCALL wincpy(WINDOW *, WINDOW *), ALTCALL disp_empty_msg(int);
  44. int ALTCALL savefiles(char far *, int), ALTCALL restorefiles(char far *, int);
  45.  
  46. /******************************************************************************
  47.  **                         W I N _ O P E N                                  **
  48.  *****************************************************************************/
  49.  
  50. win_open() {           /* open another file name display window */
  51.  
  52.    register WINDOW *wp;
  53.  
  54.    /* make sure the current window is large enough to split */
  55.  
  56.    if (cw.wrows < 6)
  57.       show_error(0,10,1,"Current window is too small to open another");
  58.  
  59.    /* allocate memory for the new window structure */
  60.  
  61.    if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
  62.       show_error(0,11,1,nomem);
  63.  
  64.    wincpy(wp,&cw);             /* initialize new window via current window */
  65.  
  66.    /* allocate memory to store files[] data */
  67.  
  68.    if ((wp->save_files = malloc_f(MAX_FILES * sizeof(FILE_ENT))) == NULL) {
  69.       free((char *)wp);
  70.       show_error(0,12,1,nomem);
  71.    }
  72.  
  73.    /*  if there is only one window open so far, create the window structure
  74.        and files[] save area to store the current window stuff */
  75.  
  76.    if (numwin == 1) {
  77.       curwin = (WINDOW *) malloc(sizeof(WINDOW));
  78.       cw.save_files = malloc_f(MAX_FILES * sizeof(FILE_ENT));
  79.       if (curwin == NULL || cw.save_files == NULL) {
  80.          free((char *)wp);
  81.          if (curwin) {
  82.             free((char *)curwin);
  83.             curwin = NULL;
  84.          }
  85.          show_error(0,13,1,nomem);
  86.       }
  87.       cw.prev = cw.next = winlis = curwin;
  88.    }
  89.  
  90.    savefiles(cw.save_files,cw.nfiles); /* save current window's files[] data */
  91.  
  92.    /* link the new window just after the current window */
  93.  
  94.    wincpy(curwin,&cw);
  95.    wp->next = curwin->next;
  96.    wp->prev = curwin;
  97.    wp->prev->next = wp;
  98.    wp->next->prev = wp;
  99.    wincpy(&cw,curwin);
  100.  
  101.    /* adjust the current window and new window display sizes */
  102.  
  103.    wp->wrows = cw.wrows / 2;           /* new is at most 1/2 of current */
  104.    cw.wrows = cw.wrows - wp->wrows;    /* current keeps whats left */
  105.    wp->fwrow = cw.fwrow + cw.wrows;    /* new start at end of current */
  106.    cw.ndrows -= wp->wrows;             /* all new rows came from name disp */
  107.    wp->fnrow = wp->fwrow + 1;          /* one overhead row for dir name */
  108.    wp->ndrows = wp->wrows - 1;
  109.  
  110.    /* adjust the top window if it was the only one and it didn't already
  111.       have a header line */
  112.  
  113.    if (numwin == 1 && !cw.showall) {
  114.       cw.fnrow++;                         /* need a line to display window */
  115.       cw.ndrows--;                        /*   directory line */
  116.       insert_line(cw.fwrow+1,cw.wrows-1); /* scroll file info down a line */
  117.       disp_dirname();                     /* disp the dir name */
  118.    }
  119.  
  120.    /* adjust old window if current item is no longer visible and turn off
  121.       the file pointer in the old window */
  122.  
  123.    if (!on_screen(cw.curidx)) {        /* adjust/redisplay window */
  124.  
  125.       adjust_window();                 /*   if current item no longer */
  126.       update_window(0);                /*   displayed */
  127.  
  128.    } else              /* not redisplaying window, turn off highlighted ptr */
  129.  
  130.       if (cw.nfiles)                      /* turn off file ptr in old window */
  131.          fp_off(cw.curidx);
  132.       else                                /* or de-highlight empty dir msg */
  133.          disp_empty_msg(0);
  134.  
  135.    /* make the new window the current one */
  136.  
  137.    wincpy(curwin,&cw);                 /* save the old current one */
  138.    wincpy(&cw,wp);                     /* new one becomes current */
  139.    curwin = wp;                        /* remember who it is */
  140.  
  141.    numwin++;                           /* one more window than there was */
  142.  
  143.    if (cw.info_display)                /* if info display is active, there */
  144.       infocnt(1);                      /*   is now 1 more info window active */
  145.  
  146.    /* only one window can be in showall mode */
  147.  
  148.    if (cw.showall) {                   /* did the old window have showall? */
  149.       cw.showall = 0;                  /* yes, turn off on this one */
  150.       getfiles();                      /* reread current dir only */
  151.       update_header();                 /* display current dir header info */
  152.    }
  153.  
  154.    /* display the file data in the new window */
  155.  
  156.    adjust_window();
  157.    update_window(1);
  158.  
  159. }
  160.  
  161.  
  162. /******************************************************************************
  163.                             W I N _ C L O S E
  164.  *****************************************************************************/
  165.  
  166. win_close() {          /* close the current window */
  167.  
  168.    int fwrowadj;
  169.    register WINDOW *wp;
  170.  
  171.    if (numwin == 1)            /* nothing to do if only one window */
  172.       return;
  173.  
  174.    /* determine the window adjustment fudge factor, 1 extra line is available
  175.       if only one window will remain and that window is not showall */
  176.  
  177.    fwrowadj = (numwin == 2 && (!anyshowall || cw.showall)) ? 0 : 1;
  178.  
  179.    /* adjust the next or prior window to take up the closing windows space
  180.       on the screen.  Always pick the next window unless current is the
  181.       last one displyed */
  182.  
  183.    if ((wp = cw.next) != winlis) {             /* next = winlis if last */
  184.  
  185.       wp->fwrow = cw.fwrow;                    /* adj nxt to take over */
  186.  
  187.    } else              /* closing last window on screen */
  188.  
  189.       wp = cw.prev;                            /* prev is current to be */
  190.  
  191.    wp->wrows += cw.wrows;              /* it has this many more rows */
  192.    wp->fnrow = wp->fwrow + fwrowadj;   /*   name display rows */
  193.    wp->ndrows = wp->wrows - fwrowadj;
  194.  
  195.    cw.next->prev = cw.prev;            /* delink the current (closing) */
  196.    cw.prev->next = cw.next;            /* windows block from window list */
  197.  
  198.    if (curwin == winlis)               /* keep track of new top window if */
  199.       winlis = wp;                     /* old top is being closed */
  200.  
  201.    if (cw.showall)                     /* turn off showall mode if this */
  202.       showoff();                       /*   window had it on */
  203.  
  204.    if (cw.info_display)                /* one less info window if this wind */
  205.       infocnt(-1);                     /*   had info display active */
  206.  
  207.    free_f(cw.save_files);              /* free the cur win's  files[] area */
  208.    free((char *)curwin);               /* free the cur/old win's block */
  209.  
  210.    /* make the next (or prior) window current, restore its files */
  211.  
  212.    wincpy(&cw,curwin = wp);
  213.    restorefiles(cw.save_files,cw.nfiles);
  214.  
  215.    numwin--;                           /* one less window now */
  216.  
  217.    /* when there is only one window, don't keep the block and files[]
  218.       save area overhead */
  219.  
  220.    if (n